﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['form', 'table', 'common', 'commonTable', 'optimizeSelectOption'], function () {
        var form = layui.form,
            table = layui.table,
            commonTable = layui.commonTable,
            common = layui.common;
        //加载数据
        wcLoading.close();
        //权限控制(js是值传递)
        currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        $("#dbNumber").bindSelect({
            url: "/SystemManage/CodeGenerator/GetDbNumberListJson",
            checked:0,
            id:""
        });
        form.render();
        commonTable.rendertable({
            elem: '#currentTableId',
            url: '/SystemManage/CodeGenerator/GetTablePageListJson',
            cols: [[
                { type: "radio", width: 50, fixed: 'left' },
                { field: 'Name', title: '表名称', width: 200 },
                { field: 'Description', title: '表备注', minWidth: 250 },
                { field: 'DbObjectType', title: '表类型', minWidth: 150,
                     templet: function (d) {
                         switch(d.DbObjectType)
                         {
                             case 0:
                                return "数据库表";
                             case 1:
                                return "数据库表";
                             default:
                                return "其他";
                         }
                     } 
                },
                { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
            ]]
        });
        var dbNumber = $('#dbNumber').val();
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            commonTable.reloadtable({
                elem: 'currentTableId',
                curr: 1,
                where: { keyword: data.field.txt_keyword,dbNumber:data.field.dbNumber}
            });
            dbNumber = data.field.dbNumber;
            return false;
        });
        //行点击事件监听，控制按钮显示
        var oneList = ["NF-entitycode", "NF-add", "NF-details"];//选择1条显示
        commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList);
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var data = table.checkStatus('currentTableId').data;
            if (obj.event === 'add') {  // 监听删除操作
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.openNewTabByIframe({
                    title: "模板代码生成",
                    href: "/SystemManage/CodeGenerator/Form?keyValue=" + data[0].Name + "&dbNumber=" + dbNumber,
                });
            }
            else if (obj.event === 'entitycode') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "实体类生成",
                    url: "/SystemManage/CodeGenerator/EntityCode?keyValue=" + data[0].Name + "&dbNumber=" + dbNumber,
                    width: "700px",
                    height: "600px",
                });
            }
            else if (obj.event === 'details') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看数据表",
                    url: "/SystemManage/CodeGenerator/Details?keyValue=" + data[0].Name + "&dbNumber=" + dbNumber,
                    width: "700px",
                    height: "600px",
                    btn: []
                });
            }
            else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                    _that.removeClass('layui-hide');
                } else {
                    _that.addClass('layui-hide');
                }
                table.resize();
            }
            return false;
        });
        //toolrow监听事件
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听
                common.openNewTabByIframe({
                    title: "模板代码生成",
                    href: "/SystemManage/CodeGenerator/Form?keyValue=" + obj.data.Name + "&dbNumber=" + dbNumber,
                });
            }
            else if (obj.event === 'entitycode') {
                common.modalOpen({
                    title: "实体类生成",
                    url: "/SystemManage/CodeGenerator/EntityCode?keyValue=" + obj.data.Name + "&dbNumber=" + dbNumber,
                    width: "700px",
                    height: "600px",
                });
            }
            else if (obj.event === 'details') {
                common.modalOpen({
                    title: "查看数据表",
                    url: "/SystemManage/CodeGenerator/Details?keyValue=" + obj.data.Name + "&dbNumber=" + dbNumber,
                    width: "700px",
                    height: "600px",
                    btn: []
                });
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset layui-hide" id="searchField">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">表名称:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">数据库编号:</label>
                            <div class="layui-input-inline">
                                <select id="dbNumber" name="dbNumber" lay-verify="required" lay-search>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" name="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>模板生成</button>
                <button id="NF-entitycode" name="NF-entitycode" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="entitycode"><i class="layui-icon">&#xe67a;</i>实体生成</button>
                <button id="NF-details" name="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
            </div>
        </script>
        <script type="text/html" id="currentTableBar">
            <a id="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i></a>
            <a id="NF-entitycode" authorize class="layui-btn layui-btn-sm " lay-event="entitycode"><i class="layui-icon">&#xe67a;</i></a>
            <a id="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal data-info-btn" lay-event="details"><i class="layui-icon">&#xe60b;</i></a>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>